package com.itheima.socket;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.*;
import java.util.ArrayList;

public class SendDemo {
    public static void main(String[] args) throws IOException {
        //创建发送端的DatagramSocket对象
        DatagramSocket ds = new DatagramSocket();

//        //创建数据并把数据打包
//        byte[] byets = "啊哈哈哈哈".getBytes();
//
//        DatagramPacket dp  = new DatagramPacket(
//                byets,//字节数组
//                byets.length,//数组长度
//                InetAddress.getByName("192.168.12.217"),//发送的IP地址
//                8888);//端口号
//        for (int i = 0; i < 10; i++) {
//            ds.send(dp);
//        }
        BufferedReader br = new BufferedReader(new FileReader("day15_inter//a.txt"));
        String line;
        while ((line=br.readLine())!=null){
            byte[] byets = line.getBytes();
            DatagramPacket dp  = new DatagramPacket(
                    byets,//字节数组
                    byets.length,//数组长度
                    InetAddress.getByName("192.168.12.217"),//发送的IP地址
                    8888);//端口号
            ds.send(dp);
        }
        ds.close();
    }
    public static void file() throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("day15_inter//a.txt"));
        String line;

        while ((line=br.readLine())!=null){
            byte[] byets = line.getBytes();
            DatagramPacket dp  = new DatagramPacket(
                    byets,//字节数组
                    byets.length,//数组长度
                    InetAddress.getByName("192.168.12.217"),//发送的IP地址
                    8888);//端口号

        }
    }
}
